package controlador;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import vista.VentanaListaUmpire;
import vista.VentanaListaUmpireTabla;
import modelo.Liga;
import modelo.Umpire;

public class ControladorVentanaListaUmpire implements ActionListener {

	private VentanaListaUmpire ventanaListaUmpire;
	private Liga liga;
	
	public ControladorVentanaListaUmpire(Liga liga) {
		super();
		ventanaListaUmpire = new VentanaListaUmpire();
		ventanaListaUmpire.setLocationRelativeTo(null);
		ventanaListaUmpire.setVisible(true);
		this.liga=liga;
		this.cargarListado();
		ventanaListaUmpire.agregarListener(this);
	}
	
   private void cargarListado(){
	  if  (liga.contarUmpires()>0){
	   ArrayList<Umpire> umpires =  liga.getUmpires();
	   ventanaListaUmpire.setListado(new VentanaListaUmpireTabla(umpires));
	  }
	  else 
	   ventanaListaUmpire.mostrarMensaje("No hay umpires registrados");
   }

   @Override
   public void actionPerformed(ActionEvent e) {
	   ControladorVentanaUmpire controladorVentanaUmpire;
	   
	   if(e.getActionCommand().equalsIgnoreCase("Registrar Umpire")){
		   ventanaListaUmpire.dispose();
		   controladorVentanaUmpire= new ControladorVentanaUmpire(liga);
	   }
	   else
		   ventanaListaUmpire.dispose();
	   }

}
